<?php
// a script to handle uploading of files - way better than the first one
// first, variables
include("basepath.php");
$dir=$_GET["dir"];

$uploaded = 0;
  
foreach ($_FILES['file']['name'] as $i => $name) 
{
 $fsize[$i]=$_FILES["file"]["size"][$i];
 if ($fsize[$i] > 8388608) // artificially low so the server doesn't reject it first
 {
  $fsizemb=round($fsize[$i]/(1024*1024),3);
  $errmess[$i] = "<font color=red>$name is too large. Size = $fsizemb MB</font>";
 }
 else
 {
  if ($_FILES['file']['error'][$i] == 0) 
  { 
   $savefilename=preg_replace("/[^a-zA-Z0-9._-s]/", "_", $_FILES['file']['name'][$i]);
   move_uploaded_file($_FILES["file"]["tmp_name"][$i], "$basepath/$dir/$savefilename");
   $uploaded++;
   }
 }
}

array_push($errmess,"<font color=green>$uploaded files uploaded successfully.</font>");
  
$msg=implode("<br>",$errmess);

header( "Refresh: 0; url=$refreshurl?dir=$dir&msg=$msg" );
// echo "<html><head><title>File Upload Complete</title>
//        <link rel='stylesheet' type='text/css' href='style.css'>
//        </head><body>" . $uploaded . " files uploaded.<br><br>"; 
// foreach ($errmess as $q)
// {
//  echo $q . "<br>";
// }
echo "</body></html>";

?> 

